// DlgAddRequest.cpp : implementation file
//

#include "stdafx.h"
#include "Celsus.h"
#include "DlgAddRequest.h"
#include "DlgPickUser.h"
#include "DlgSendRequest.h"
#include "DlgComplete.h"
#include "DlgSendFileHtml.h"
#include "DlgPreviewHTML.h"
#include "SendMessage.h"

// CDlgAddRequest dialog

IMPLEMENT_DYNAMIC(CDlgAddRequest, CDialog)

CDlgAddRequest::CDlgAddRequest(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgAddRequest::IDD, pParent)
	, m_szUserEmail(_T(""))
	, m_dServiceFee(0)
	, m_dCopyrightFee(0)
	, m_bAtLibrary(FALSE)
	, m_szInstructions(_T(""))
	, m_szRequest(_T(""))
	, m_szInformation(_T(""))
	, m_szProject(_T(""))
	, m_bEmailUser(TRUE)
{
	m_nUserID = -1;
	m_nExternalID = -1;
	m_nStaffID = -1;
	m_bShowThumbnail = FALSE;
	m_bEnableThumbnail = FALSE;
}

CDlgAddRequest::~CDlgAddRequest()
{
	m_pszaMethod = NULL;
	m_pszaCollection = NULL;
}

void CDlgAddRequest::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_USER_NAME, m_szUserEmail);
	DDX_Text(pDX, IDC_EDIT_FEE_SERVICE, m_dServiceFee);
	DDX_Text(pDX, IDC_EDIT_FEE_COPYRIGHT, m_dCopyrightFee);
	DDX_Control(pDX, IDC_COMBO_LIBRARY, m_ctrlLibrary);
	DDX_Control(pDX, IDC_COMBO_PRIORITY, m_ctrlPriority);
	DDX_Control(pDX, IDC_COMBO_METHOD, m_ctrlMethod);
	DDX_Check(pDX, IDC_CHECK_AT_LIBRARY, m_bAtLibrary);
	DDX_Text(pDX, IDC_EDIT_INSTRUCTIONS, m_szInstructions);
	DDX_Text(pDX, IDC_EDIT_REQUEST, m_szRequest);
	DDX_Text(pDX, IDC_EDIT_INFORMATION, m_szInformation);
	DDX_Text(pDX, IDC_EDIT_PROJECT, m_szProject);
	DDX_Control(pDX, IDC_COMBO_COLLECTION, m_ctrlCollection);
	DDX_Control(pDX, IDC_COMBO_REFERRALS, m_ctrlReferrals);
	DDX_Control(pDX, IDC_COMBO_COPYRIGHT, m_ctrlCopyright);
	DDX_Control(pDX, IDC_COMBO_ILL, m_ctrlILL);
	DDX_Check(pDX, IDC_CHECK_EMAIL_USER, m_bEmailUser);
}


BEGIN_MESSAGE_MAP(CDlgAddRequest, CDialog)
	ON_CBN_SELCHANGE(IDC_COMBO_PRIORITY, &CDlgAddRequest::OnCbnSelchangeComboPriority)
	ON_CBN_SELCHANGE(IDC_COMBO_METHOD, &CDlgAddRequest::OnCbnSelchangeComboMethod)
	ON_BN_CLICKED(IDC_BUTTON_SEND_FILE, &CDlgAddRequest::OnBnClickedButtonSendFile)
END_MESSAGE_MAP()


// CDlgAddRequest message handlers

BOOL CDlgAddRequest::OnInitDialog()
{
	CDialog::OnInitDialog();

	ASSERT( m_pszaCollection != NULL );
	ASSERT( m_pszaMethod != NULL );

	CDlgPickUser dlgPickUser;
	// enable add button
	dlgPickUser.m_bAdd = TRUE;
	if( dlgPickUser.DoModal() == IDOK )
	{
		// set user filter
		m_szUserEmail = dlgPickUser.m_szEmail;
	}
	else
	{
		EndDialog( IDCANCEL );
		return TRUE;
	}

	USER_SET User;
	INT nCurSel = 0;
	INT nSel = 0;
	CString szTemp;

	// get user set
	if( !appConfig.m_SQL.GetUserSet( &User, m_szUserEmail ))
	{
		AfxMessageBox( _T("ERROR getting user.") );
		EndDialog( IDCANCEL );
		return TRUE;
	}

	// user id
	m_nUserID = User.m_id;
	m_nExternalID = User.m_external_id;
	// set current
	m_szUserEmail = User.m_email;

	// set m_ctrlLibrary
	for( INT nIndex = 0; nIndex < m_pszaLibrary->GetCount(); nIndex++ )
	{
		szTemp = m_pszaLibrary->GetAt( nIndex );
		if( !szTemp.IsEmpty() )
		{
			nSel = m_ctrlLibrary.AddString( szTemp );
			m_ctrlLibrary.SetItemData( nSel, nIndex );
			// check for current library
			if( User.m_library_id != ID_TRG && User.m_library_id == nIndex )
				nCurSel = nSel;
			else if( m_nCurrentLibrary != ID_TRG && m_nCurrentLibrary == nIndex )
				nCurSel = nSel;
		}
	}
	m_ctrlLibrary.SetCurSel( nCurSel );

	//m_ctrlPriority
	for( INT nIndex = 0; nIndex < m_pszaPriority->GetCount(); nIndex++ )
	{
		szTemp = m_pszaPriority->GetAt( nIndex );
		if( !szTemp.IsEmpty() )
		{
			nSel = m_ctrlPriority.AddString( szTemp );
			m_ctrlPriority.SetItemData( nSel, nIndex );
		}
	}
	m_ctrlPriority.SetCurSel( 0 );

	// get priority fee
	PRIORITY_LOOKUP Priority;
	appConfig.m_SQL.GetDescriptionPriority( &Priority, m_ctrlPriority.GetItemData( m_ctrlPriority.GetCurSel() ));
	m_dServiceFee += Priority.dServiceFee;

	//m_ctrlMethod
	for( INT nIndex = 0; nIndex < m_pszaMethod->GetCount(); nIndex++ )
	{
		szTemp = m_pszaMethod->GetAt( nIndex );
		if( !szTemp.IsEmpty() )
		{
			nSel = m_ctrlMethod.AddString( szTemp );
			m_ctrlMethod.SetItemData( nSel, nIndex );
			if( User.m_method_id == nIndex )
				nCurSel = nSel;
		}
	}
	m_ctrlMethod.SetCurSel( nCurSel );

	// get priority fee
	METHOD_LOOKUP Method;
	appConfig.m_SQL.GetDescriptionMethod( &Method, m_ctrlMethod.GetItemData( m_ctrlMethod.GetCurSel() ));
	m_dServiceFee += Method.dServiceFee;

	// set m_ctrlCollection
	for( INT nIndex = 0; nIndex < m_pszaCollection->GetCount(); nIndex++ )
	{
		szTemp = m_pszaCollection->GetAt( nIndex );
		if( !szTemp.IsEmpty() )
		{
			nSel = m_ctrlCollection.AddString( szTemp );
			m_ctrlCollection.SetItemData( nSel, nIndex );
			//if( m_nCollectionID == nIndex )
			//	nCurSel = nSel;
		}
	}
	m_ctrlCollection.SetCurSel( nCurSel );

	//m_ctrlReferrals
	for( INT nIndex = 0; nIndex < m_pszaReferrals->GetCount(); nIndex++ )
	{
		szTemp = m_pszaReferrals->GetAt( nIndex );
		if( !szTemp.IsEmpty() )
		{
			nSel = m_ctrlReferrals.AddString( szTemp );
			m_ctrlReferrals.SetItemData( nSel, nIndex );
			if( User.m_referrals == nIndex )
				nCurSel = nSel;
		}
	}
	m_ctrlReferrals.SetCurSel( nCurSel );

	//m_ctrlCopyright
	for( INT nIndex = 0; nIndex < m_pszaCopyright->GetCount(); nIndex++ )
	{
		szTemp = m_pszaCopyright->GetAt( nIndex );
		if( !szTemp.IsEmpty() )
		{
			nSel = m_ctrlCopyright.AddString( szTemp );
			m_ctrlCopyright.SetItemData( nSel, nIndex );
			if( User.m_copyright == nIndex )
				nCurSel = nSel;
		}
	}
	m_ctrlCopyright.SetCurSel( nCurSel );

	//m_ctrlILL
	for( INT nIndex = 0; nIndex < m_pszaILL->GetCount(); nIndex++ )
	{
		szTemp = m_pszaILL->GetAt( nIndex );
		if( !szTemp.IsEmpty() )
		{
			nSel = m_ctrlILL.AddString( szTemp );
			m_ctrlILL.SetItemData( nSel, nIndex );
		}
	}
	m_ctrlILL.SetCurSel( 0 );

	// get library info
	LIBRARY_LOOKUP Library;
	appConfig.m_SQL.GetDescriptionLibrary( &Library, m_nCurrentLibrary );
	m_szFrom = Library.szEmail;
	m_szName = Library.szName;
	m_szSubject = Library.szSubject;

	// disable ILL
	if( appConfig.m_Options.bDisableILL )
	{
		GetDlgItem( IDC_STATIC_ILL )->ShowWindow( SW_HIDE );
		GetDlgItem( IDC_COMBO_ILL )->ShowWindow( SW_HIDE );
	}
	// Disable Referrals
	if( appConfig.m_Options.bDisableReferrals )
	{
		GetDlgItem( IDC_STATIC_REFERRALS )->ShowWindow( SW_HIDE );
		GetDlgItem( IDC_COMBO_REFERRALS )->ShowWindow( SW_HIDE );		
	}
	// Disable Copyright
	if( appConfig.m_Options.bDisableCopyright )
	{
		GetDlgItem( IDC_STATIC_COPYRIGHT )->ShowWindow( SW_HIDE );
		GetDlgItem( IDC_COMBO_COPYRIGHT )->ShowWindow( SW_HIDE );
	}
	// Disable Copyright
	if( appConfig.m_Options.bDisableFinacial )
	{
		GetDlgItem( IDC_STATIC_FEE_SERVICE )->ShowWindow( SW_HIDE );
		GetDlgItem( IDC_STATIC_FEE_COPYRIGHT )->ShowWindow( SW_HIDE );
		GetDlgItem( IDC_EDIT_FEE_SERVICE )->ShowWindow( SW_HIDE );
		GetDlgItem( IDC_EDIT_FEE_COPYRIGHT )->ShowWindow( SW_HIDE );
	}
	// disable at library
	if( appConfig.m_Options.bDisableAtLibrary )
		GetDlgItem( IDC_CHECK_AT_LIBRARY )->ShowWindow( SW_HIDE );


	// set email
	m_bEmailUser = appConfig.m_Email.bSendEmailOnAdd;

	// update data
	UpdateData( FALSE );

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgAddRequest::OnOK()
{
	// update
	UpdateData();

	CString szTemp;
	CString szAddTemplate;
	CString szRequests;
	CStringArray szaRequests;
	REQUEST_SET newRequest;
	CSendMessage SendMsg;
	CFilePair aFiles;
	LONG nRequestID = 0;

	// get libary
	m_ctrlLibrary.GetWindowText( szTemp );
	m_nCurrentLibrary = m_ctrlLibrary.GetItemData( m_ctrlLibrary.GetCurSel() );

	// remove tabs
	m_szRequest.Remove( '\t' );

	// split string
	appConfig.SplitString( m_szRequest, _T("\n\r\n\r"), szaRequests );

	// get add file text
	if( !appConfig.m_General.szRequestAddFile.IsEmpty() )
		szAddTemplate = appConfig.ReadFile( appConfig.m_General.szRequestAddFile );

	// loop through requests
	for( INT nIndex = 0; nIndex < szaRequests.GetCount(); nIndex++ )
	{
		// get request
		CString szRequest = szaRequests.GetAt( nIndex );
		// trim request
		szRequest.Trim();

		if( !szRequest.IsEmpty() )
		{
			// get empty request
			appConfig.m_SQL.GetEmptyRequest( &newRequest );

			COleDateTime time(COleDateTime::GetCurrentTime());
			// set request
			newRequest.m_request = szRequest;
			// set variables
			newRequest.m_user_id = m_nUserID;
			newRequest.m_date_in = time;
			newRequest.m_atlibrary = m_bAtLibrary;
			newRequest.m_instructions = m_szInstructions;
			newRequest.m_information = m_szInformation;
			newRequest.m_manual = 1;
			newRequest.m_fee_copyright = m_dCopyrightFee;
			newRequest.m_fee_service = m_dServiceFee;
			newRequest.m_project = m_szProject;

			// get library
			newRequest.m_library_id = m_ctrlLibrary.GetItemData( m_ctrlLibrary.GetCurSel() );
			if( newRequest.m_library_id < 0 )
				return;
			// get priority
			newRequest.m_priority_id = m_ctrlPriority.GetItemData( m_ctrlPriority.GetCurSel() );
			if( newRequest.m_priority_id < 0 )
				return;
			// get method
			newRequest.m_method_id = m_ctrlMethod.GetItemData( m_ctrlMethod.GetCurSel() );
			if( newRequest.m_method_id < 0 )
				return;
			// get collection
			newRequest.m_collection_id = m_ctrlCollection.GetItemData( m_ctrlCollection.GetCurSel() );
			if( newRequest.m_collection_id < 0 )
				return;
			// get referrals
			newRequest.m_referrals = m_ctrlReferrals.GetItemData( m_ctrlReferrals.GetCurSel() );
			if( newRequest.m_referrals < 0 )
				return;
			// get copyright
			newRequest.m_copyright = m_ctrlCopyright.GetItemData( m_ctrlCopyright.GetCurSel() );
			if( newRequest.m_copyright < 0 )
				return;
			// get ills
			newRequest.m_ill_id = m_ctrlILL.GetItemData( m_ctrlILL.GetCurSel() );
			if( newRequest.m_ill_id < 0 )
				return;

			// add request
			if( m_nExternalID > 0 )
			{
				REQUEST_SET localRequest = newRequest;
				// insert into local first
				appConfig.m_SQL.SetRequestSet( &localRequest, -1, TRUE );
				// set external_id for insert into external
				newRequest.m_external_id = localRequest.m_id;
				// insert into external
				appConfig.m_SQL.SetExternalRequestSet( &newRequest, -1, TRUE  );
				// set external id for local request
				localRequest.m_external_id = newRequest.m_id;
				// update local with external id
				appConfig.m_SQL.SetRequestSet( &localRequest );

				// set request ID for macros and history
				nRequestID = localRequest.m_id;
			}
			else
			{
				// add request
				appConfig.m_SQL.SetRequestSet( &newRequest, -1, TRUE );
				// set request ID for macros and history
				nRequestID = newRequest.m_id;
			}

			// update add text
			if( !szAddTemplate.IsEmpty() )
			{
				szTemp = szAddTemplate;
				appConfig.FormatMacros( &szTemp, nRequestID, m_nStaffID, newRequest.m_status_id, newRequest.m_library_id, m_nUserID );
				szRequests += szTemp;
			}

			// set file pair for request count
			FILE_PAIR Files;
			aFiles.Add( Files );

			// write history
			appConfig.UpdateRequestHistory( nRequestID, m_nStaffID, newRequest.m_status_id, _T("Request Added by Staff") );
		}
	}

	// email use
	if( m_bEmailUser )
	{
		// get file
		m_szMessage = appConfig.ReadFile( appConfig.m_Email.szAddMessageFile );

		// format message
		appConfig.FormatMacros( &m_szMessage, -1, m_nStaffID, STATUS_ID_NEW, m_nCurrentLibrary, m_nUserID, &aFiles );
		// format subject macros
		appConfig.FormatMacros( &m_szSubject, -1, m_nStaffID, STATUS_ID_NEW, m_nCurrentLibrary, m_nUserID, &aFiles );

		// requests macro
		m_szMessage.Replace( _T("(REQUEST_ADDED)"), szRequests );

		CDlgPreviewHTML dlgPreview;
		dlgPreview.m_bSend = TRUE;
		dlgPreview.m_szHTML = m_szMessage;
		dlgPreview.m_szSubject = m_szSubject;
		
		// show message
		if( dlgPreview.DoModal() != IDOK )
		{
			// end dialog as requests already added
			CDialog::OnOK();
			return;
		}

		// get new message
		m_szMessage = dlgPreview.m_szHTML;
		m_szSubject = dlgPreview.m_szSubject;

		// send it
		if( !SendMsg.SendEmail( m_szName, m_szFrom, m_szUserEmail, m_szSubject, m_szMessage ))
		{
			AfxMessageBox( _T("Send Dialog: Requests added but there was an error sending the email"), MB_OK );
			CDialog::OnOK();
			return;
		}
	}

	CDialog::OnOK();
}

void CDlgAddRequest::OnCancel()
{
	// TODO: Add your specialized code here and/or call the base class

	CDialog::OnCancel();
}

void CDlgAddRequest::OnBnClickedButtonSendFile()
{
	// update
	UpdateData();

	CString szTemp;
	CStringArray szaRequests;
	REQUEST_SET newRequest;

	// remove tabs
	m_szRequest.Remove( '\t' );

	// split string
	appConfig.SplitString( m_szRequest, _T("\n\r\n\r"), szaRequests );

	// only one for now
	if( szaRequests.GetCount() > 1 )
	{
		AfxMessageBox( _T("You can only send one request a time.\n\r\n\rAdjust request to continue.") );
		return;
	}

	// loop through requests
	for( INT nIndex = 0; nIndex < szaRequests.GetCount(); nIndex++ )
	{
		// get request
		CString szRequest = szaRequests.GetAt( nIndex );
		// trim request
		szRequest.Trim();

		// if not empty send
		if( !szRequest.IsEmpty() )
		{
			// get empty request
			appConfig.m_SQL.GetEmptyRequest( &newRequest );

			COleDateTime time(COleDateTime::GetCurrentTime());
			// set request
			newRequest.m_request = szRequest;
			// set variables
			newRequest.m_user_id = m_nUserID;
			newRequest.m_date_in = time;
			newRequest.m_atlibrary = m_bAtLibrary;
			newRequest.m_instructions = m_szInstructions;
			newRequest.m_information = m_szInformation;
			newRequest.m_manual = 1;
			newRequest.m_fee_copyright = m_dCopyrightFee;
			newRequest.m_fee_service = m_dServiceFee;
			newRequest.m_project = m_szProject;

			// get library
			newRequest.m_library_id = m_ctrlLibrary.GetItemData( m_ctrlLibrary.GetCurSel() );
			if( newRequest.m_library_id < 0 )
				return;
			// get priority
			newRequest.m_priority_id = m_ctrlPriority.GetItemData( m_ctrlPriority.GetCurSel() );
			if( newRequest.m_priority_id < 0 )
				return;
			// get method
			newRequest.m_method_id = m_ctrlMethod.GetItemData( m_ctrlMethod.GetCurSel() );
			if( newRequest.m_method_id < 0 )
				return;
			// get collection
			newRequest.m_collection_id = m_ctrlCollection.GetItemData( m_ctrlCollection.GetCurSel() );
			if( newRequest.m_collection_id < 0 )
				return;
			// get referrals
			newRequest.m_referrals = m_ctrlReferrals.GetItemData( m_ctrlReferrals.GetCurSel() );
			if( newRequest.m_referrals < 0 )
				return;
			// get copyright
			newRequest.m_copyright = m_ctrlCopyright.GetItemData( m_ctrlCopyright.GetCurSel() );
			if( newRequest.m_copyright < 0 )
				return;
			// get ills
			newRequest.m_ill_id = m_ctrlILL.GetItemData( m_ctrlILL.GetCurSel() );
			if( newRequest.m_ill_id < 0 )
				return;

			// add request
			appConfig.m_SQL.SetRequestSet( &newRequest, -1, TRUE );

			// check it
			if( newRequest.m_id <= 0 )
			{
				AfxMessageBox( _T("There was an error adding the request. Please retry.") );
				return;
			}

			// send request
			REQUEST_SET currentRequest;
			appConfig.m_SQL.GetRequestSet( &currentRequest, newRequest.m_id );

			// check send type
			METHOD_LOOKUP Method;
			appConfig.m_SQL.GetDescriptionMethod( &Method, currentRequest.m_method_id );
			if( Method.nElectronic == 0 )
			{
				CDlgComplete dlgComplete;
				// set variables
				dlgComplete.m_nItemID = currentRequest.m_id;
				dlgComplete.m_nStaffID = m_nStaffID;
				dlgComplete.m_nLibraryID = m_nCurrentLibrary;
				dlgComplete.m_pszaCollection = m_pszaCollection;
				// show dialog
				if( dlgComplete.DoModal() == IDOK )
				{
					// write history
					appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Sent to user") );
				}
			}
			else
			{
				if( appConfig.m_General.bSendFilesViaHTTP )
				{
					CDlgSendFileHtml dlgSend;
					// set variables
					dlgSend.m_nItemID = currentRequest.m_id;
					dlgSend.m_nStaffID = m_nStaffID;
					dlgSend.m_nLibraryID = m_nCurrentLibrary;
					// show dialog
					if( dlgSend.DoModal() == IDOK )
					{
						// write history
						appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgSend.m_nStatus, _T("Sent to web server via HTTP") );
					}
				}
				else
				{
					CDlgSendRequest dlgSend;
					// set variables
					dlgSend.m_nItemID = currentRequest.m_id;
					dlgSend.m_nStaffID = m_nStaffID;
					dlgSend.m_nLibraryID = m_nCurrentLibrary;
					dlgSend.m_bShowThumbnail = m_bShowThumbnail;
					dlgSend.m_bEnableThumbnail = m_bEnableThumbnail;

					dlgSend.m_pszaStatus = m_pszaStatus;
					dlgSend.m_pszaPriority = m_pszaPriority;
					dlgSend.m_pszaMethod = m_pszaMethod;
					dlgSend.m_pszaLibrary = m_pszaLibrary;
					dlgSend.m_pszaCollection = m_pszaCollection;
					dlgSend.m_pszaReferrals = m_pszaReferrals;
					dlgSend.m_pszaCopyright = m_pszaCopyright;
					dlgSend.m_pszaILL = m_pszaILL;

					// show dialog
					if( dlgSend.DoModal() == IDOK )
					{
						// write history
						if( dlgSend.m_nSendType == 0 )
							appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgSend.m_nStatus, _T("Sent to web server") );
						else if( dlgSend.m_nSendType == 1 )
							appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgSend.m_nStatus, _T("Sent as attachment") );
						else
							appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgSend.m_nStatus, _T("Sent to user") );
					}
					else
					{
						// canceled, return
						return;
					}
				}
			}
		}
	}
	// end dialog
	CDialog::OnOK();
}

void CDlgAddRequest::OnCbnSelchangeComboPriority()
{
	LONG nID;
	CString szTemp;
	DOUBLE dFeeTotal = 0;

	// update data
	UpdateData();

	// get priority id
	nID = m_ctrlPriority.GetItemData( m_ctrlPriority.GetCurSel() );
	if( nID >= 0 )
	{
		// get method fee
		PRIORITY_LOOKUP Priority;
		appConfig.m_SQL.GetDescriptionPriority( &Priority, nID );
		dFeeTotal += Priority.dServiceFee;
	}

	// check method
	nID = m_ctrlMethod.GetItemData( m_ctrlMethod.GetCurSel() );
	if( nID >= 0 )
	{
		// get method fee
		METHOD_LOOKUP Method;
		appConfig.m_SQL.GetDescriptionMethod( &Method, nID );
		dFeeTotal += Method.dServiceFee;
	}

	// set new total
	m_dServiceFee = dFeeTotal;
	// update data
	UpdateData( FALSE );
}

void CDlgAddRequest::OnCbnSelchangeComboMethod()
{
	LONG nID;
	CString szTemp;
	DOUBLE dFeeTotal = 0;

	// update data
	UpdateData();

	// get priority id
	nID = m_ctrlPriority.GetItemData( m_ctrlPriority.GetCurSel() );
	if( nID >= 0 )
	{
		// get method fee
		PRIORITY_LOOKUP Priority;
		appConfig.m_SQL.GetDescriptionPriority( &Priority, nID );
		dFeeTotal += Priority.dServiceFee;
	}

	// get method id
	nID = m_ctrlMethod.GetItemData( m_ctrlMethod.GetCurSel() );
	if( nID >= 0 )
	{
		// get priority fee
		METHOD_LOOKUP Method;
		appConfig.m_SQL.GetDescriptionMethod( &Method, nID );
		dFeeTotal += Method.dServiceFee;
	}

	// set new total
	m_dServiceFee = dFeeTotal;
	// update data
	UpdateData( FALSE );
}
